#pragma once
#include <iostream>
#include <mutex>
#include "mutex.hpp"
namespace mycond
{
    using namespace myMutex;
    class Cond
    {
        public:
            Cond()
            {
               int n =  pthread_cond_init(&_cond, nullptr);
                if (n != 0)
                {
                     std::cerr << "pthread_cond_init failed" << std::endl;
                }
            }

            void Wait(Mutex &mutex)
            {

                int n = pthread_cond_wait(&_cond, mutex.getMutex());
                if (n != 0)
                {
                    std::cerr << "pthread_cond_wait failed" << std::endl;
                }
            }

            void notifyone()
            {
                int n = pthread_cond_signal(&_cond);
                if (n != 0)
                {
                    std::cerr << "pthread_cond_signal failed" << std::endl;
                }
            }
            void notifyall()
            {
                int n = pthread_cond_broadcast(&_cond);
                if (n != 0)
                {
                    std::cerr << "pthread_cond_broadcast failed" << std::endl;
                }
            }
            ~Cond()
            {
                int n = pthread_cond_destroy(&_cond);
                if (n != 0)
                {
                    std::cerr << "pthread_cond_destroy failed" << std::endl;
                }
            }


        private:
            pthread_cond_t _cond;

    };

} // namespace mycond

